package com.cgbl.cg.adapter

import android.os.Bundle
import com.blankj.utilcode.util.ColorUtils
import com.cgbl.cg.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.configs.AppConstants
import com.robot.base.model.ResourceBean
import com.robot.base.util.arouter.ARouterUtil
import com.robot.base.utils.pic.ImageLoaderUtils

class SearchResourceAdapter : BaseQuickAdapter<ResourceBean, BaseViewHolder>(R.layout.app_item_search_resource) {
    override fun convert(holder: BaseViewHolder, item: ResourceBean) {
        holder.setText(R.id.item_tv_name, item.name)
            .setText(R.id.item_tv_prompt, item.resourceFormat)
        holder.setText(
            R.id.item_tv_price, when (item.free) {
                "1" -> {
                    holder.setTextColor(R.id.item_tv_price, ColorUtils.getColor(R.color.app_color_cc2d2d))
                    "免费"
                }
                "2" -> {
                    holder.setTextColor(R.id.item_tv_price, ColorUtils.getColor(R.color.app_color_ffc063))
                    "VIP限免"
                }
                else -> {
                    holder.setTextColor(R.id.item_tv_price, ColorUtils.getColor(R.color.app_color_cc2d2d))
                    "¥${item.naturalPrice}"
                }
            }
        )
        ImageLoaderUtils.displayRound(context, holder.getView(R.id.item_iv_1), item.coverUrl, 8)
        holder.itemView.setOnClickListener {
            ARouterUtil.goToActivityWithBundle(AppConstants.Router.Mine.A_MINE_RESOURCE_PROFILE,
                Bundle().apply {
                    putString("id", item.id)
                }
            )
        }
    }

}